#define DEBUG

#include <stdio.h>
#include "id3.h"

int main ( int argc, char *argv[] )
{
	FILE *mp3File;
	char buffer[HEADER_LENGTH];
	char check = 0;
	
	mp3InfoStruct v, *mp3Info;
	mp3Info = &v;

	if (argc != 2)
	{
		printf("Usage <filename>");
	}
	else
	{
		mp3File = fopen(argv[1], "rb");

		#ifdef DEBUG
		if (mp3File == 0) 
		{
			printf("Invalid file selected\n");
		}
		else
		{
			fgets(buffer, HEADER_LENGTH+1, mp3File);			
			
			printf("File opened successfully!");
			printf("Checking if it is a valid mp3 with a tag...\n");

			check = id3ValidCheck(buffer);
			if (check == MP3_FILE_TAG_FOUND)
			{
				printf("Valid MP3 tag found!!\n");
			}
			else
			{
				printf("No MP3 tag found!\n");
			}
			
			id3getTagSize(buffer, mp3Info);
			id3GetFileSize(mp3Info, argv[1]);;
			id3GetFrame(argv[1], mp3Info);

			printf("%s\n", v.id3Title);

			//printf("File size of the MP3 file is %f MB\n", (v.infoFileSize * 9.53e-7) );
			//printf("The first header is %s\n", v.infoFrame); 
			//printf("The string is %s\n", v.strFileName);
			//id3GetAlbum(buffer, mp3Info.infoTagSize, id3InfoPointer);
			//printf("The size of the ID3 tag is %i kilobytes\n", mp3Info.infoTagSize/1024);
			getchar();
		}
		#endif /* DEBUG */

		//close file before exiting
		if (mp3File != NULL)
		{
			if ( (fclose(mp3File)) == 0 )
			{
				printf("File did not successfully close\n");
			}
		}
	}
	return 0;
}